#include "MRay.h"
#include "world.h"
#include "Camera.h"

mray::MRay::MRay(const std::string& sceneXMLPath)
{
	mp_world = new World;
	mp_world->Initialize(sceneXMLPath);
}

mray::MRay::~MRay()
{
	delete mp_world;
}

int mray::MRay::width()
{
	return mp_world->m_width;
}

int mray::MRay::height()
{
	return mp_world->m_height;
}

unsigned char* mray::MRay::render(int cameraId)
{
	return mp_world->Render(cameraId);
}

void mray::MRay::move(int cameraId, float dis, Move act)
{
	Camera& cam = mp_world->GetCamera(cameraId);
	switch(act){
	case Forward:
		cam.Move(cam.m_look, dis);
		break;
	case Backward:
		cam.Move(cam.m_look, -dis);
		break;
	case Up:
		cam.Move(cam.m_up, dis);
		break;
	case Down:
		cam.Move(cam.m_up, -dis);
		break;
	case Left:
		cam.Move(cam.m_right, -dis);
		break;
	case Right:
		cam.Move(cam.m_right, dis);
		break;
	}
}

void mray::MRay::rotate(int cameraId, float radian, Move act)
{
	Camera& cam = mp_world->GetCamera(cameraId);
	switch(act){
	case Up:
		cam.Rotate(cam.m_right, -radian);
		break;
	case Down:
		cam.Rotate(cam.m_right, radian);
		break;
	case Left:
		cam.Rotate(UNIT_AXIS_Y, -radian);
		break;
	case Right:
		cam.Rotate(UNIT_AXIS_Y, radian);
		break;
	}
}


